package com.example.analysis.service.impl;

import com.example.analysis.entity.Competition;
import com.example.analysis.mapper.CompetitionDao;
import com.example.analysis.service.CompeteService;
import com.example.analysis.utils.Response;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class CompeteServiceImpl implements CompeteService {

    @Resource
    private CompetitionDao competitionDao;

    @Override
    public Response<Competition> insert(Competition aCompetition) {
        try {
            competitionDao.insert(aCompetition);
            return new Response<>(true, "Insert success", null);
        } catch (Exception e) {
            return new Response<>(false, "Insert failed: " + e.getMessage(), null);
        }
    }

    @Override
    public Response<Competition> getById(String CompetitionId) {
        Competition aCompetition = competitionDao.selectByPrimaryKey(CompetitionId);
        if (aCompetition != null) {
            return new Response<>(true, "Success", aCompetition);
        } else {
            return new Response<>(false, "Administration not found", null);
        }
    }

    @Override
    public Response<Competition> getByName(String CompetitionName) {
        Competition aCompetition = competitionDao.selectByName(CompetitionName);
        if (aCompetition != null) {
            return new Response<>(true, "Success", aCompetition);
        } else {
            return new Response<>(false, "Administration not found", null);
        }
    }
}
